var userdb = require('../../db/user.db')
var logger = require('../../logger')
var emit = require('../../emit')
var async = require('async')

function onsocket(socket, data) {
    //desc 描述(项目名)、 active 1=启用 0=禁用
    //[{"user":"ZZYY","pwd":"zy","desc":"zydesc","active":1}]
    async.waterfall([
        (callback) => {
            userdb.getalluser((err, response) => {
                callback(err, response);
            })
        },
        (users, callback) => {
            var results = new Array();
            async.forEach(users, (r, cb) => {
                userdb.getuser(r, (err, info) => {
                    if (err) {
                        cb(err);
                    } else {
                        info.user = r;
                        results.push(info);
                        cb(null);
                    }
                })
            }, (err) => {
                callback(err,results);                
            })
        }
    ],(err,results)=>{
        if (err) {
            emit.send(socket, "alluser", null);
        } else {
            emit.send(socket, "alluser", results);
        }
    });
}

module.exports = {
    onsocket
}